package ui.panels.commands;

import javax.swing.JPanel;

import ui.flowManager.FlowManagerImpl;
import ui.flowManager.expirimentProperties.ExperimentProperties.Agent_Group;
import ui.panels.ThirdPanel;
import ui.panels.primary.adaptiveAgentProperties.AdaptiveAgentProperties;
import ui.panels.primary.playerProperties.PlayerPropertiesPanel_2;

import gameEngine.agents.distrebution.representation.DistributionRepresentation;

/**
 * @author vladimir && alon
 *	The class is set DistRepresentation in Player Properties Panel
 *	The creation of this command is designed for use distributions GUI, to set the distribution 
 */
public class SetDistRepresentationCommand implements Command{

	private DistributionRepresentation 	distRepresentation = null;
	private Agent_Group					group = null;
	
	public void execute()
	{
		if(distRepresentation != null && group != null)
		{
			//get the last created panel  
			JPanel panel = FlowManagerImpl.getInstance().getLastPanel();
			//check that this is third panel - the panel that split to 3 parts
			if(panel instanceof ThirdPanel)
			{
				//cast
				ThirdPanel thirdPanel = (ThirdPanel) panel;
				//get the player properties panel
				panel = thirdPanel.getLastPanelCreated();
				//case is control player
				if(group == Agent_Group.CONTROL_AGENT && panel instanceof PlayerPropertiesPanel_2)
				{
					//cast and set the distribution
					PlayerPropertiesPanel_2 propertiesPanel = (PlayerPropertiesPanel_2) panel;
					propertiesPanel.setDistRepresentation(distRepresentation);
				}
				//case is studied player
				else if (group == Agent_Group.STUDIED_AGENT && panel instanceof AdaptiveAgentProperties)
				{
					AdaptiveAgentProperties propertiesPanel = (AdaptiveAgentProperties) panel;
					propertiesPanel.setDistRepresentation(distRepresentation);
				}
			}
		}
		//end first if
	}

	public void setDistRepresentation(DistributionRepresentation distRepresentation) {
		this.distRepresentation = distRepresentation;
	}

	public void setGroup(Agent_Group group) {
		this.group = group;
	}
}
